import { createRouter, createWebHistory } from "vue-router"
import { Admin_info } from "@/utils/Local"
const routes = [
    {
        path: '/',
        redirect: '/home'
    },
    {
        path: '/home',
        component: () => import("@/views/Home/Home.vue"),
        redirect: '/home/essay',
        children: [
            {
                path: 'essay',
                component: () => import("@/views/Home/Stack/Essay/Essay.vue"),
                meta: {
                    keepAlive: true //需要缓存
                },
            },
            {
                path: 'routine',
                component: () => import("@/views/Home/Stack/Routine.vue"),
                meta: {
                    keepAlive: true //需要缓存
                }

            },
            {
                path: 'media',
                component: () => import("@/views/Home/Stack/Media.vue"),
                meta: {
                    keepAlive: true //需要缓存
                }

            }
        ]

    },
    {
        path: '/essay_detail/:id',
        component: () => import("@/views/Details/Essay_Detail.vue")
    },
    {
        path: '/routine_detail/:id',
        component: () => import("@/views/Details/Routine_Detail.vue")
    },
    {
        path: "/video_detail/:id",
        component: () => import("@/views/Details/Video_detail.vue")
    },
    {
        path: "/albums",
        component: () => import("@/views/Albums/Albums.vue")
    },
    {
        path: "/message",
        component: () => import("@/views/Message/Message.vue")
    },
    {
        path: "/user",
        component: () => import("@/views/User/User.vue"),

    },
    {
        path: "/speak",
        component: () => import("@/views/Speak/Speak.vue")
    },
    {
        path: "/back",
        component: () => import("@/views/Backstage/Backstage.vue"),
        redirect: '/back/users/admin',
        children: [
            {
                path: "users/admin",
                component: () => import("@/views/Backstage/Users/Admin.vue"),
                meta: {
                    isto: false
                }
            },
            {
                path: "users/user",
                component: () => import("@/views/Backstage/Users/User.vue"),
                meta: {
                    isto: false
                }
            },
            {
                path: "article/blog",
                component: () => import("@/views/Backstage/Article/Blog.vue"),
                meta: {
                    isto: false
                }
            },
            {
                path: "media/music",
                component: () => import("@/views/Backstage/Media/Music.vue"),
                meta: {
                    isto: false
                }
            },
            {
                path: "media/video",
                component: () => import("@/views/Backstage/Media/Video.vue"),
                meta: {
                    isto: false
                }
            },
            {
                path: "other/message",
                component: () => import("@/views/Backstage/Other/Messages.vue"),
                meta: {
                    isto: false
                }
            },
            {
                path: "other/albums",
                component: () => import("@/views/Backstage/Other/Albums.vue"),
                meta: {
                    isto: false
                }
            },
            {
                path: "other/speaks",
                component: () => import("@/views/Backstage/Other/Speaks.vue"),
                meta: {
                    isto: false
                }
            },
            {
                path: "other/discuss",
                component: () => import("@/views/Backstage/Other/Discuss.vue"),
                meta: {

                }
            },
            {
                path: "edit_video",
                component: () => import("@/views/Backstage/Edit/Edit_Video.vue")
            },
            {
                path: "edit_music",
                component: () => import("@/views/Backstage/Edit/Essay_edit.vue")
            },
            {
                path: "update_music/:_id",
                component: () => import("@/views/Backstage/Edit/Essay_update.vue")
            },
            {
                path: "update_Video/:_id",
                component: () => import("@/views/Backstage/Edit/update_Video.vue")
            }
        ]
    },
    {
        path: "/login",
        name: "login",
        component: () => import("@/views/Login/Login.vue")
    },


]
const router = createRouter({
    history: createWebHistory(),
    routes,

})
router.beforeEach((to, from, next) => {
    from
    if (to.path == '/back' || to.meta.isto == false) {
        if (Admin_info.Get_info()) {
            next()

        } else {
            next("/login")

        }

    } else {
        //去登陆页面之前
        if (to.path == '/login') {
            //如果登录过
            if (Admin_info.Get_info()) {
                next('/back')
                return

            } else {
                next()
                return
            }
        }
        next()

    }

})

// 跳转路由守卫



export default router